<template>
  <div class="autumn-container">
    <!-- 面包 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/system/menu/menuList' }">菜单列表</el-breadcrumb-item>
      <el-breadcrumb-item>菜单信息</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <div class="autumn-center">
      <div class="edit-form">
        <el-form label-width="90px" size="large" disabled :model="editForm">

          <el-row>
            <el-col :span="12">
              <el-form-item label="上级" prop="parentId">
                <autumn-tree-select size="large" :data="treeMenus" :defaultKey="editForm.parentId" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="名称" prop="name">
                <el-input v-model="editForm.name" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="排序" prop="sort">
                <el-input type="number" v-model="editForm.sort" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="连接" prop="href">
                <el-input v-model="editForm.href" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="类型" prop="target">
                <el-radio-group v-model="editForm.target">
                  <el-radio v-for="(value, key, index) in $listDict('MENU_TARGET')" :key="index" :label="key">{{ value
                  }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="图标" prop="icon">
                <e-icon-picker style="width:100%;" disabled v-model="editForm.icon" size="large" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="权限" prop="permission">
                <el-input v-model="editForm.permission" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" resize="none" v-model="editForm.remark" />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>

        <div class="form-foot-button">
          <el-button @click="cancel">返回</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { listMenu, viewMenu } from 'src/api/system/menu'
import { $listDict } from 'src/hooks/useCommon'

// 查看菜单
const editForm = reactive({
  id: '',
  parentId: 1,
  name: '',
  sort: 1,
  href: '',
  target: 'CATALOG',
  icon: '',
  permission: '',
  remark: ''
})

const route = useRoute()
if (route.query.id) {
  const id = route.query.id as string
  viewMenu(id).then(({ data }) => {
    Object.assign(editForm, data)
  })
}

// 菜单树形结构
const treeMenus = ref<Array<any>>([])
listMenu().then(({ data }) => {
  treeMenus.value = data
})

// 返回
const router = useRouter()
function cancel() {
  router.push('/system/menu/menuList')
}

</script>

<style lang="scss" scoped>
</style>
